package com.huluobo.a2203kotlinshopping

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.huluobo.a2203kotlinshopping.databinding.ActivityMainBinding
import com.huluobo.base.view.BaseActivity

/**
 * 使用Navigation搭建主页面,总结:
 * 1.倒依赖
 * 2.res下创建Navigation的文件夹,创建Navigation图表
 * 3.添加几个fragment在图表中
 * 4.创建menu,有几个fragment就写几个item,********注意********* item的id必须和图表中的fragment的id一直,否则找不到对应的页面
 * 5.在main的xml中拉出一个控件NavHostFragment,直接拉,然后修改为Fragment
 * 6.给生成的NavHostFragment添加刚刚创建图表,也就是main_nav
 * 7,设置底部导航和导航器的联动
 */
class MainActivity : BaseActivity<ActivityMainBinding>() {
    override fun initData() {
    }

    override fun initView() {
        //获取导航宿主fragment
        val navHostFragment = supportFragmentManager.findFragmentById(R.id.main_nav_host_fragment) as NavHostFragment
        //获取导航器
        val navController = navHostFragment.navController
        //给底部导航添加导航器
        dataBinding.mainBottomNav.setupWithNavController(navController)
    }

    override fun getLayoutId(): Int = R.layout.activity_main
}